package com.ruoyi.personnel.salary.monthly.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.personnel.salary.monthly.domain.MonthlyCond;
import com.ruoyi.personnel.salary.monthly.domain.MonthlyDomain;
import com.ruoyi.personnel.salary.monthly.domain.MonthlyDto;
import com.ruoyi.personnel.salary.monthly.service.IMonthlyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 控制层
 */
@RestController
@RequestMapping("/salary/monthly")
@Api(value = "月薪模块", tags = "月薪接口")
public class MonthlyController extends BaseController {
    @Autowired
    private IMonthlyService monthlyService;

    /**
     * 获取月薪列表
     * @return
     */
    @ApiOperationSupport(includeParameters = {"MonthlyCond.salaryMonthlyId", "MonthlyCond.staffId", "MonthlyCond.salaryDate"})
    @ApiOperation(value = "获取月薪列表",notes = "查询所有月薪信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MonthlyCond cond) {
        startPage();
        List<MonthlyDto> monthlyDtos = monthlyService.selectMonthlyList(cond);
        return getDataTable(monthlyDtos);
    }

    /**
     * 新增月薪
     *
     * @param monthly
     * @return
     */
    @ApiOperation(value = "新增月薪记录", notes = "新增月薪信息")
    @ApiImplicitParam(name = "monthly", value = "新增工资计算记录", dataType = "MonthlyDomain")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody MonthlyDomain monthly) {
        return toAjax(monthlyService.insertMonthly(monthly));
    }

    /**
     * 修改月薪记录
     *
     * @param monthly
     * @return
     */
    @ApiOperation(value = "修改月薪记录", notes = "修改月薪记录信息")
    @ApiImplicitParam(name = "monthly", value = "修改月薪记录(可修改参数：monthlySalary、remark)", dataType = "MonthlyDomain")
    @PostMapping("/edit")
    public AjaxResult edit(@Validated @RequestBody MonthlyDomain monthly) {
        return toAjax(monthlyService.updateMonthly(monthly));
    }

    /**
     * 删除月薪记录
     * 仅修改删除标志位
     *
     * @param monthly
     * @return
     */
    @ApiOperation(value = "删除月薪记录", notes = "删除月薪记录,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody MonthlyDomain monthly) {
        return toAjax(monthlyService.updateMonthlyDeleteFlag(monthly));
    }

    /**
     * 读取月薪
     * @param staffId
     * @return
     */
//    @ApiOperation(value = "读取月薪", notes = "读取月薪方法")
//    @GetMapping("/{staffId}")
//    public AjaxResult readMonthlySalary(@PathVariable String staffId) {
//        Map<String, Double> map = new HashMap<>();
//        Double monthlySalary = monthlyService.readMonthlySalary(staffId);
//        map.put("monthlySalary", monthlySalary);
//        return AjaxResult.success("查询成功", map);
//    }
}
